#pragma once

#include <AVUIMarkupExtension.h>

namespace AVUI {

/// <summary>Implements a markup extension that supports dynamic resource references made from XAML. </summary>
class DynamicResourceExtension : public MarkupExtension
{
public:
    DECLARE_ELEMENT(DynamicResourceExtension, Object);

#pragma region Public Methods

    /// <summary>Initializes a new instance of the <see cref="T:System.Windows.DynamicResourceExtension" /> class.</summary>
    DynamicResourceExtension() { };

    /// <summary>Initializes a new instance of the <see cref="T:System.Windows.DynamicResourceExtension" /> class, with the provided initial key.</summary>
    /// <param name="resourceKey">The key of the resource that this markup extension references.</param>
    DynamicResourceExtension(Object* pResourceKey);

    /// <summary>Returns an object that should be set on the property where this extension is applied. For <see cref="T:System.Windows.DynamicResourceExtension" />, this is the object found in a resource dictionary in the current parent chain that is keyed by the <see cref="P:System.Windows.DynamicResourceExtension.ResourceKey" />.</summary>
    /// <returns>The object to set on the property where the extension is applied. Rather than the actual value, this will be an expression that will be evaluated at a later time.</returns>
    /// <param name="serviceProvider">Object that can provide services for the markup extension.</param>
    /// <exception cref="T:System.InvalidOperationException">Attempted to provide a value for an extension that did not provide a <paramref name="resourceKey" />.</exception>
    virtual TRefCountedPtr<Object> ProvideValue(IServiceProvider* pServiceProvider) AVUI_OVERRIDE;

#pragma endregion Public Methods

#pragma region Public Properties

    /// <summary>Gets or sets the key specified by this dynamic resource reference. The key is used to lookup a resource in resource dictionaries, by means of an intermediate expression. </summary>
    /// <returns>The resource key that this dynamic resource reference specifies.</returns>
    Object* get_ResourceKey() { return m_pResourceKey; }
    void set_ResourceKey(Object* pValue);

#pragma endregion Public Properties

private:

#pragma region Private Fields

    TRefCountedPtr<Object> m_pResourceKey;

#pragma endregion Private Fields

};

}; // namespace AVUI

